#include <iostream>
#include <unistd.h>
#include <vector>
#include "Thread.hpp"

using namespace ThreadMoudle;

void Print(const std::string &name)
{
    int cnt = 1;
    while(true)
    {
        std::cout << name << "is running, cnt: " << cnt++ << std::endl;   
        sleep(1);
        
    }
}

const int gnum = 10;

int main()
{
    // 构建线程对象
    std::vector<Thread> threads;
    for(int i = 0; i < gnum; ++i)
    {
        std::string name = "thread-" + std::to_string(i + 1);
        threads.emplace_back(name, Print);
        sleep(1);
    }
    
    for(auto &thread : threads)
    {
        thread.Start();
    }

    sleep(10);

    for(auto &thread : threads)
    {
        thread.Stop();
    }

    for(auto &thread : threads)
    {
        thread.Join();
    }
    return 0;
}

/*
int main()
{
    Thread t("thread-1", Print);

    t.Start();
    std::cout << t.Name() << ", status: " << t.Status() << std::endl;
    sleep(10);
    std::cout << t.Name() << ", status: " << t.Status() << std::endl;
    t.Stop();
    sleep(1);
    std::cout << t.Name() << ", status: " << t.Status() << std::endl;

    t.Join();
    std::cout << "join done" << std::endl;

    return 0;
}
*/